package gokyesil.game.aygitciklar.model;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class Earth extends Box 
{
	public float dimX;
	public float dimY;

	public Earth(World physWorld, float _posX, float _posY, float _width, float _height)
	{
		health = 1.1f;
		width = 1.6f;
		height = 1.6f;
		density = 1.0f;
		dimX = _width;
		dimY = _height;
		BodyDef bodyDef = new BodyDef();
	    bodyDef.type = BodyType.StaticBody;
		bodyDef.position.set(_posX+width*dimX/2.0f, _posY+height*dimY/2.0f);
	    body = physWorld.createBody(bodyDef);
	    PolygonShape dynamicBox = new PolygonShape();
	    dynamicBox.setAsBox(width*dimX/2.0f, height*dimY/2.0f);
	    FixtureDef fixtureDef = new FixtureDef();
	    fixtureDef.shape = dynamicBox;
	    fixtureDef.density = density; 
	    fixtureDef.friction = 0.3f;
	    fixtureDef.restitution = 0.3f;
	    body.createFixture(fixtureDef);
	}
	public void render(SpriteBatch spriteBatch, TextureRegion _textureRegion)
	{
		for(int i=0; i<dimX; i++)
		{
			for(int j=0; j<dimY; j++)
			{
				spriteBatch.draw(_textureRegion, body.getPosition().x-width*dimX/2.0f+i*width, body.getPosition().y-height*dimY/2.0f+j*height, width/2.0f, height/2.0f, width, height, 1, 1, body.getAngle());
			}
		}
		
	}

}
